using VCards.Models;
using VCards.Serializer;
using VCards.Types;

namespace VCards.Processors;

public static class SortStringProcessor
{
    public static string Serialize(VCard vcard)
    {
        //Please note that the property "SORT-STRING" only exists for VCardVersion 3.0
        //where VCardVersion 4.0 uses "SORT-AS" key in N property
        if (vcard.Version != VCardVersion.V3)
        {
            return string.Empty;
        }

        if (string.IsNullOrWhiteSpace(vcard.SortString))
        {
            return string.Empty;
        }

        return DefaultSerializer.GetVCardString("SORT-STRING", vcard.SortString, true, vcard.Version);
    }

    public static void Parse(Token token, ref VCard vcard)
    {
        if (!string.IsNullOrWhiteSpace(vcard.SortString))
        {
            return;
        }

        vcard.SortString = token.Values[0];
    }
}